﻿using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Security.Cryptography;
using System.Xml.Linq;
using System.Web.Security;
using System.Text;
using BonSaiTableAdapters;

public partial class admin_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string LoginName = txtLoginName.Text.Trim();
        string password = txtPassword.Text.Trim();
        ASCIIEncoding ascEn = new ASCIIEncoding();
        SHA512Managed sha512 = new SHA512Managed();
        byte[] bInput = ascEn.GetBytes(password);
        string encodedPass = ascEn.GetString(sha512.ComputeHash(bInput));

        AdminsTableAdapter adminDA = new AdminsTableAdapter();
        BonSai.AdminsDataTable adminDT = adminDA.GetAdminByNameAndPass(LoginName,encodedPass);

        if (adminDT.Rows.Count > 0)
        {
            BonSai.AdminsRow adminRow = adminDT.Rows[0] as BonSai.AdminsRow;
            if (adminRow.RoleStatus == 0)
            {
                lblMessage.Text = "Tài khoản của bạn đã bị khóa !";
            }
            else
            {
                Session["adminID"] = adminRow.AdminID.ToString();
                Session["admin_loginName"] = adminRow.LoginName;
                Session["admin_fullName"] = adminRow.FullName;

                Response.Redirect("ProductManage.aspx");
            }
        }
        else
        {
            lblMessage.Text = "Tên đăng nhập hoặc mật khẩu không đúng !";
        }
    }
}
